package com.fr.chart.axis;

import com.fr.base.StringUtils;
import com.fr.base.XMLable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GlyphCondition;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.Glyph;
import com.fr.chart.core.glyph.TextGlyph;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.SeriesAttr;
import com.fr.chart.plot.SeriesCollection;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.parameter.Parameter;
import com.fr.report.script.Calculator;
import com.fr.report.script.ParameterMapNameSpace;
import com.fr.util.Utils;
import java.awt.Shape;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.text.DecimalFormat;
import java.text.Format;

public class DataLabelInfo
  implements XMLable, GlyphCondition
{
  private static final long serialVersionUID = 1945411573328281811L;
  public static final String XML_TAG = "DataLabel";
  public static final String valuePara = "${VALUE}";
  public static final String categoryPara = "${CATEGORY}";
  public static final String seriesPara = "${SERIES}";
  public static final String percentPara = "${PERCENT}";
  private SeriesAttrContents seriesLabelContents = new SeriesAttrContents();
  private SeriesAttrPosition seriesLabelPosition = new SeriesAttrPosition();
  private SeriesAttrStyle seriesLabelStyle = new SeriesAttrStyle();
  private boolean showLegendItem = false;

  public void setSeriesLabelContents(SeriesAttrContents paramSeriesAttrContents)
  {
    this.seriesLabelContents = paramSeriesAttrContents;
  }

  public SeriesAttrContents getSeriesLabelContents()
  {
    return this.seriesLabelContents;
  }

  public void setSeriesLabel(String paramString)
  {
    this.seriesLabelContents.setSeriesLabel(paramString);
  }

  public String getSeriesLabel()
  {
    return this.seriesLabelContents.getSeriesLabel();
  }

  public void setSeriesLabelPosition(SeriesAttrPosition paramSeriesAttrPosition)
  {
    this.seriesLabelPosition = paramSeriesAttrPosition;
  }

  public SeriesAttrPosition getSeriesLabelPosition()
  {
    return this.seriesLabelPosition;
  }

  public void setPosition(int paramInt)
  {
    this.seriesLabelPosition.setPosition(paramInt);
  }

  public int getPosition()
  {
    return this.seriesLabelPosition.getPosition();
  }

  public void setSeriesLabelStyle(SeriesAttrStyle paramSeriesAttrStyle)
  {
    this.seriesLabelStyle = paramSeriesAttrStyle;
  }

  public SeriesAttrStyle getSeriesLabelStyle()
  {
    return this.seriesLabelStyle;
  }

  public void setSeparation(String paramString)
  {
    this.seriesLabelStyle.setSeparation(paramString);
  }

  public String getSeparation()
  {
    return this.seriesLabelStyle.getSeparation();
  }

  public void setTextAttr(TextAttr paramTextAttr)
  {
    this.seriesLabelStyle.setTextAttr(paramTextAttr);
  }

  public TextAttr getTextAttr()
  {
    return this.seriesLabelStyle.getTextAttr();
  }

  public void setFormat(Format paramFormat)
  {
    this.seriesLabelStyle.setFormat(paramFormat);
  }

  public Format getFormat()
  {
    return this.seriesLabelStyle.getFormat();
  }

  public void setShowLegendItem(boolean paramBoolean)
  {
    this.showLegendItem = paramBoolean;
  }

  public boolean isShowLegendItem()
  {
    return this.showLegendItem;
  }

  public void setShowGuidLine(boolean paramBoolean)
  {
    this.seriesLabelContents.setShowGuidLine(paramBoolean);
  }

  public boolean isShowGuidLine()
  {
    return this.seriesLabelContents.isShowGuidLine();
  }

  public void add2SeriesAttr(SeriesAttr paramSeriesAttr)
  {
    paramSeriesAttr.addCondition(getSeriesLabelContents());
    paramSeriesAttr.addCondition(getSeriesLabelPosition());
    paramSeriesAttr.addCondition(getSeriesLabelStyle());
  }

  public Glyph createDataLabel(DataPoint paramDataPoint)
  {
    String str = createLabelText(paramDataPoint);
    TextGlyph localTextGlyph = new TextGlyph(str, getSeriesLabelStyle().getTextAttr());
    Rectangle2D localRectangle2D = preferredLabelBounds(localTextGlyph, paramDataPoint, getSeriesLabelPosition().getPosition());
    localTextGlyph.setBounds(localRectangle2D);
    return localTextGlyph;
  }

  public String createLabelText(DataPoint paramDataPoint)
  {
    String str1 = "";
    if (getSeriesLabelContents().getSeriesLabel() != null)
    {
      try
      {
        Object localObject1;
        Object localObject2;
        Calculator localCalculator = Calculator.createCalculator();
        if (getSeriesLabelStyle().getPercentFormat() != null)
          localObject1 = getSeriesLabelStyle().getPercentFormat();
        else
          localObject1 = new DecimalFormat("00%");
        String str2 = ((Format)localObject1).format(Double.valueOf(Utils.doubleToString(paramDataPoint.getPercentValue())));
        if (getSeriesLabelStyle().getFormat() != null)
          localObject2 = getSeriesLabelStyle().getFormat().format(new Double(paramDataPoint.getValue()));
        else
          localObject2 = new Double(paramDataPoint.getValue());
        Parameter[] arrayOfParameter = { new Parameter("Category", getSeriesLabelStyle().getSeparation() + paramDataPoint.getCategoryName()), new Parameter("Series", getSeriesLabelStyle().getSeparation() + paramDataPoint.getSeriesName()), new Parameter("Value", getSeriesLabelStyle().getSeparation() + Utils.objectToString(localObject2)), new Parameter("Percent", getSeriesLabelStyle().getSeparation() + str2) };
        localCalculator.pushNameSpace(ParameterMapNameSpace.create(arrayOfParameter));
        str1 = localCalculator.renderTpl(getSeriesLabelContents().getSeriesLabel());
      }
      catch (Exception localException)
      {
      }
      if (str1.startsWith(getSeriesLabelStyle().getSeparation()))
        str1 = str1.substring(1);
    }
    return ((String)(String)str1);
  }

  public static Rectangle2D preferredLabelBounds(TextGlyph paramTextGlyph, DataPoint paramDataPoint, int paramInt)
  {
    Rectangle2D.Double localDouble = null;
    Dimension2D localDimension2D = paramTextGlyph.preferredDimension();
    Rectangle2D localRectangle2D = paramDataPoint.getShape().getBounds2D();
    if (paramInt == 4)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + localRectangle2D.getWidth(), localRectangle2D.getY() + (localRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 1)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() - localDimension2D.getHeight(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 2)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() - localDimension2D.getWidth(), localRectangle2D.getY() + (localRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 3)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() + localRectangle2D.getHeight(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 0)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() + (localRectangle2D.getHeight() - localDimension2D.getHeight()) / 2.0D, localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 7)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() + localRectangle2D.getHeight() - localDimension2D.getHeight(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 5)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else if (paramInt == 6)
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() - localDimension2D.getHeight(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    else
      localDouble = new Rectangle2D.Double(localRectangle2D.getX() + (localRectangle2D.getWidth() - localDimension2D.getWidth()) / 2.0D, localRectangle2D.getY() - localDimension2D.getHeight(), localDimension2D.getWidth() + 4.0D, localDimension2D.getHeight());
    return localDouble;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        String str3 = getSeriesLabel();
        if (((str2 = paramXMLableReader.getAttr("cateName")) != null) && (Boolean.valueOf(str2).booleanValue()))
          str3 = "${CATEGORY}";
        if (((str2 = paramXMLableReader.getAttr("seriesName")) != null) && (Boolean.valueOf(str2).booleanValue()))
          if (str3 != null)
            str3 = str3 + "${SERIES}";
          else
            str3 = "${SERIES}";
        if (((str2 = paramXMLableReader.getAttr("showValue")) != null) && (Boolean.valueOf(str2).booleanValue()))
          if (str3 != null)
            str3 = str3 + "${VALUE}";
          else
            str3 = "${VALUE}";
        if (((str2 = paramXMLableReader.getAttr("piePercent")) != null) && (Boolean.valueOf(str2).booleanValue()))
          if (str3 != null)
            str3 = str3 + "${PERCENT}";
          else
            str3 = "${PERCENT}";
        if ((str2 = paramXMLableReader.getAttr("showItem")) != null)
          this.showLegendItem = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("position")) != null)
          getSeriesLabelPosition().setPosition(Byte.parseByte(str2));
        if ((str2 = paramXMLableReader.getAttr("seriesLabel")) != null)
          getSeriesLabelContents().setSeriesLabel(str2);
        if ((str2 = paramXMLableReader.getAttr("guidLine")) != null)
          getSeriesLabelContents().setShowGuidLine(Boolean.valueOf(str2).booleanValue());
      }
      else if ("Separation".equals(str1))
      {
        this.seriesLabelStyle.setSeparation(paramXMLableReader.getElementValue());
      }
      else if ("TextAttr".equals(str1))
      {
        this.seriesLabelStyle.setTextAttr((TextAttr)paramXMLableReader.readXMLObject(new TextAttr()));
      }
      else if ("Format".equals(str1))
      {
        this.seriesLabelStyle.setFormat(ReportXMLUtils.readFormat(paramXMLableReader));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("DataLabel");
    paramXMLPrintWriter.startTAG("Attr").attr("position", getPosition()).attr("showItem", this.showLegendItem);
    if (getSeriesLabel() != null)
      paramXMLPrintWriter.attr("seriesLabel", getSeriesLabel());
    paramXMLPrintWriter.end();
    if (StringUtils.isNotEmpty(getSeparation()))
      paramXMLPrintWriter.startTAG("Separation").textNode(getSeparation()).end();
    if (getTextAttr() != null)
      getTextAttr().writeXML(paramXMLPrintWriter);
    if (getFormat() != null)
      ReportXMLUtils.writeFormat(paramXMLPrintWriter, getFormat());
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    DataLabelInfo localDataLabelInfo = (DataLabelInfo)super.clone();
    if (getTextAttr() != null)
      localDataLabelInfo.setTextAttr((TextAttr)getTextAttr().clone());
    if (getFormat() != null)
      localDataLabelInfo.setFormat((Format)getFormat().clone());
    return localDataLabelInfo;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof DataLabelInfo))
      return false;
    DataLabelInfo localDataLabelInfo = (DataLabelInfo)paramObject;
    if (!(Equals.equals(localDataLabelInfo.getSeriesLabel(), getSeriesLabel())))
      return false;
    if (localDataLabelInfo.getPosition() != getPosition())
      return false;
    if (!(Equals.equals(localDataLabelInfo.getFormat(), getFormat())))
      return false;
    if (!(Equals.equals(localDataLabelInfo.getSeparation(), getSeparation())))
      return false;
    return (Equals.equals(localDataLabelInfo.getTextAttr(), getTextAttr()));
  }

  public void dealCondition(SeriesCollection paramSeriesCollection, int paramInt)
  {
    SeriesAttrContents localSeriesAttrContents = (SeriesAttrContents)paramSeriesCollection.getSeriesCondition(new SeriesAttrContents(), paramInt);
    setSeriesLabelContents(localSeriesAttrContents);
    SeriesAttrPosition localSeriesAttrPosition = (SeriesAttrPosition)paramSeriesCollection.getSeriesCondition(new SeriesAttrPosition(), paramInt);
    setSeriesLabelPosition(localSeriesAttrPosition);
    SeriesAttrStyle localSeriesAttrStyle = (SeriesAttrStyle)paramSeriesCollection.getSeriesCondition(new SeriesAttrStyle(), paramInt);
    setSeriesLabelStyle(localSeriesAttrStyle);
  }
}